package treeSet;

import java.util.Set;
import java.util.TreeSet;

public class TreeSetMethod {
	public static void main(String[] args) {
		Set<Fruit> set=new TreeSet<Fruit>();
		set.add(new Fruit("apple",10));
		set.add(new Fruit("pear",9));
		set.add(new Fruit("banana",8));
		set.add(new Fruit("straberry",7));
		set.add(new Fruit("orange",8));
		for (Object object : set) {
			p(object);
		}
	}
    static void p(Object o){
    	System.out.println(o);
    }
}
class Fruit implements Comparable<Fruit>{
	String name;
	int    sweet;
	public Fruit() {
	}
	public Fruit(String name, int sweet) {
		super();
		this.name = name;
		this.sweet = sweet;
	}
	@Override
	public String toString() {
		return this.name+"  "+this.sweet;
	}
	@Override
	public int compareTo(Fruit o) {
		if(this.sweet==o.sweet)
			return this.name.compareTo(o.name);
		return this.sweet-o.sweet;
	}
}
